package demo1;

import entity.Constant;

/**
 * 配置1：-Xms5m -Xmx20m -XX:+PrintGCDetails -XX:+UseSerialGC -XX:+PrintCommandLineFlags
 *
 */
public class Test01 {

	public static void main(String[] args) {

		// 查看GC信息
		System.out.println("-----------------------------------------------------");
		System.out.println("最大内存:" + Runtime.getRuntime().maxMemory() / Constant.NUM1024);
		System.out.println("空闲内存:" + Runtime.getRuntime().freeMemory() / Constant.NUM1024);
		System.out.println("总内存:" + Runtime.getRuntime().totalMemory() / Constant.NUM1024);
		System.out.println("-----------------------------------------------------");

		byte[] b1 = new byte[1 * 1024 * 1024];
		System.out.println("分配了1M");
		System.out.println("最大内存:" + Runtime.getRuntime().maxMemory() / Constant.NUM1024);
		System.out.println("空闲内存:" + Runtime.getRuntime().freeMemory() / Constant.NUM1024);
		System.out.println("总内存:" + Runtime.getRuntime().totalMemory() / Constant.NUM1024);
		System.out.println("-----------------------------------------------------");

		byte[] b2 = new byte[4 * 1024 * 1024];
		System.out.println("分配了4M");
		System.out.println("最大内存:" + Runtime.getRuntime().maxMemory() / Constant.NUM1024);
		System.out.println("空闲内存:" + Runtime.getRuntime().freeMemory() / Constant.NUM1024);
		System.out.println("总内存:" + Runtime.getRuntime().totalMemory() / Constant.NUM1024);
		System.out.println("-----------------------------------------------------");

	}

}
